/* Name: ExitBtn
 * Author: Cameron Hoerig
 * Date: 5-13-12
 * Description: The ExitBtn class allows the user to exit the game
 * Revisions: See Subversion logs at http://code.google.com/p/software-engineering-2012/source/list
 */

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;

public class ExitBtn extends Button {
	private int width; // width of the button
	private int height; // height of the button
	
	// Creates an exit button at the given location
	public ExitBtn(int px, int py, int pwidth, int pheight) {
		super(px, py, pwidth, pheight); // set the placement, width, and height to the Button class
		Game.create((Item)this, 1); // Needed for update, draw, and destroy
		colType = COL_NONE; // Needed for collision checking
		width = pwidth; // set width and height
		height = pheight;
	}
	
	// Called when the button is pressed - sets the visual elements, and plays sound.
	protected void pressed() {
		Sound.effect(Sound.EFFECT_CLICK);
		Game.quitGame();	// if the button is pressed, exit the game	
	}
	
	// Called every time a new frame is drawn - draws the button when it is marked as visible
	public void draw() { // draw the button
		Graphics2D gh = Game.getGraphicsHandle();
		if (btnDrawState == Button.BTN_STATE_OFF) {gh.setColor(Color.GRAY);} // if no activity, button is gray
		else if (btnDrawState == Button.BTN_STATE_HOVER) {gh.setColor(Color.LIGHT_GRAY);} // if mouse is hovering over button, make button light gray
		else {gh.setColor(Color.DARK_GRAY);} // if button has been pressed, change color to dark gray
		gh.fillRoundRect(x, y, width, height, 15, 15); // fill the button with appropriate shade of gray
		gh.setFont(new Font("Serif", Font.PLAIN, 40));
		gh.setColor(Color.BLUE);
		String text = "EXIT"; // text to be placed over button
		FontRenderContext frc = gh.getFontRenderContext();
		Rectangle2D rect = gh.getFont().getStringBounds(text, frc);
		gh.drawChars(text.toCharArray(), 0, text.length(), (int)(x + width/2 - rect.getWidth()/2), (int)(y + height/2 + rect.getHeight()/2)-10); // add text to button
	}
	
	public void update() {updateBtn();}
	public void leftMousePress() {leftMousePressBtn();}
	public void leftMouseRelease() {leftMouseReleaseBtn();}
}